package com.yuhong.reggie.mapper;

import com.yuhong.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {
    //删除购物车
    @Delete("delete from shopping_cart where id=#{id}")
    Integer delete(Long id);

    //根据用户id查询购物车
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findAllByUserId(Long userId);

    //根据菜品id或套餐id查询
    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);

    //更新指定购物车数据数量
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    Integer updateNumber(@Param("id") Long id, @Param("number") Integer number);

    //插入新的一条购物车数据
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId}" +
            ",#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(ShoppingCart shoppingCart);
}
